function t(t, e, a) {
    return e in t ? Object.defineProperty(t, e, {
        value: a,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = a, t;
}

function e(t, e) {
    return e.map(function(e) {
        for (var a = e.split(t).map(function(t) {
            return {
                val: t
            };
        }), o = [ a.shift() ]; a.length; ) o.push({
            val: t,
            key: !0
        }), o.push(a.shift());
        return {
            words: o,
            val: e
        };
    });
}

var a = function() {
    function t(t, e) {
        var a = [], o = !0, n = !1, r = void 0;
        try {
            for (var i, s = t[Symbol.iterator](); !(o = (i = s.next()).done) && (a.push(i.value), 
            !e || a.length !== e); o = !0) ;
        } catch (t) {
            n = !0, r = t;
        } finally {
            try {
                !o && s.return && s.return();
            } finally {
                if (n) throw r;
            }
        }
        return a;
    }
    return function(e, a) {
        if (Array.isArray(e)) return e;
        if (Symbol.iterator in Object(e)) return t(e, a);
        throw new TypeError("Invalid attempt to destructure non-iterable instance");
    };
}(), o = require("../../utils/formvalid-config"), n = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("../../utils/api2")), r = "/images/default/logo.png", i = getApp(), s = {
    create: {
        chooseLogo: function() {
            var t = this;
            wx.chooseImage({
                count: 1,
                sizeType: [ "compressed" ],
                success: function(e) {
                    var o = a(e.tempFilePaths, 1)[0];
                    t.setData({
                        logo: o,
                        logoAutoGenerating: !1,
                        "form.logo": o
                    });
                }
            });
        }
    },
    setting: {
        chooseLogo: function() {
            var t = this;
            wx.showActionSheet({
                itemList: [ "上传图片", "自动生成" ],
                success: function(e) {
                    var o = e.tapIndex;
                    if (0 === o) wx.chooseImage({
                        count: 1,
                        sizeType: [ "compressed" ],
                        success: function(e) {
                            var o = a(e.tempFilePaths, 1)[0];
                            t.setData({
                                logo: o
                            });
                        }
                    }); else if (1 === o) {
                        var n = t.data.autoLogo;
                        t.setData({
                            logo: n
                        });
                    }
                }
            });
        }
    }
};

Component({
    options: {
        multipleSlots: !0
    },
    properties: {
        mode: {
            type: String,
            observer: function(t) {
                "setting" === t && this.setData({
                    logoAutoGenerating: !1
                });
            }
        },
        name: {
            type: String,
            observer: function(t) {
                this.setData({
                    "form.name": t,
                    logoChar: (0, o.getLogoChar)(t)
                });
            }
        },
        logo: {
            type: String,
            value: r,
            observer: function(t) {
                this.setData({
                    "form.logo": t
                });
            }
        },
        companyname: {
            type: String,
            observer: function(t) {
                this.setData({
                    "form.companyname": t
                });
            }
        },
        tel: {
            type: String,
            observer: function(t) {
                this.setData({
                    "form.tel": t
                });
            }
        },
        submitText: String,
        version: {
            type: String,
            observe: function(t) {
                this.setData({
                    "form.version": t
                });
            }
        }
    },
    data: {
        logoChar: "",
        autoLogo: r,
        logoAutoGenerating: !0,
        searchingCN: "",
        companyList: [],
        companyListShow: !1,
        form: {
            name: "",
            companyname: "",
            tel: "",
            logo: r
        },
        isIniOS: i.globalData.isIniOS
    },
    methods: {
        input: function(e) {
            var a = e.detail.value, n = e.currentTarget.dataset.key;
            switch (this.setData(t({}, "form." + n, a)), n) {
              case "name":
                this.setData({
                    logoChar: (0, o.getLogoChar)(a)
                });
                break;

              case "companyname":
                this.searchCN(a), this.tryGetTel(a);
            }
        },
        clear: function(e) {
            var a = e.currentTarget.dataset.key;
            switch (this.setData(t({}, "form." + a, "")), a) {
              case "name":
                this.setData({
                    logoChar: ""
                });
            }
        },
        chooseLogo: function() {
            var t = this.properties.mode;
            s[t].chooseLogo.apply(this, arguments);
        },
        getAutoLogo: function(t) {
            var e = t.detail.value;
            this.setData({
                autoLogo: e
            }), this.data.logoAutoGenerating && this.setData({
                logo: e
            });
        },
        hideCNList: function() {
            this.setData({
                companyListShow: !1
            });
        },
        simulateBlur: function() {},
        selectCN: function(t) {
            var e = t.currentTarget.dataset.cn;
            this.setData({
                companyname: e,
                companyListShow: !1,
                companyList: [],
                "form.companyname": e
            }), this.tryGetTel(e);
        },
        formSubmit: function(t) {
            var e = this.data.form, a = t.currentTarget.dataset.trial;
            (0, o.validateForm)(e) && (e.trial = +a, this.triggerEvent("submit", {
                value: e
            }));
        },
        collectinfo: function() {
            var t = this.data, e = t.version, a = t.logo, o = t.companyname, n = t.tel;
            wx.navigateTo({
                url: "/pages/site-create/collectinfo/collectinfo?version=" + e + "&logo=" + a + "&companyname=" + o + "&tel=" + n
            });
        },
        viewClause: function(t) {
            var e = t.currentTarget.dataset.type;
            wx.navigateTo({
                url: "/pages/site-create/selectversion/clause/clause?type=" + e
            });
        },
        searchCN: function(t) {
            var a = this;
            this.setData({
                searchingCN: t
            }), t ? n.default.v4.receipt.searchsuggest({
                data: {
                    keyword: t
                }
            }).then(function(o) {
                var n = o.lists;
                a.data.searchingCN === t && a.setData({
                    companyListShow: !0,
                    companyList: e(t, n)
                });
            }) : this.setData({
                companyList: []
            });
        },
        tryGetTel: function(t) {
            var e = this;
            t && n.default.v4.receipt.getcompanytaxnumber({
                data: {
                    keyword: t
                }
            }).then(function(t) {
                var a = t.lists.mobile;
                a && e.setData({
                    tel: a,
                    "form.tel": a
                });
            });
        }
    }
});